<?php
// +----------------------------------------------------------------------
// | YZCMS <XueHen CMS>
// +----------------------------------------------------------------------
// | Copyright (c) http://www.xuehen.org
// +----------------------------------------------------------------------
// | Author XueHen <490860758@qq.com>
// +----------------------------------------------------------------------
namespace Admin\Controller;
define('TYPE','slide');

class SlideController extends BaseController{
	function index(){
		$db = M('link');
		$result = $db->order('ord desc , id asc')->where("`type` = '".TYPE."'")->select();
		$this->assign('content',$result);
		$this->display();
    }
	
	//添加成功
	function addok(){	
		$db = M('link');
		$_POST['type'] = TYPE;
		$db->create();
		$rid = $db->add();
		if($rid){
			$this->success('添加成功!','index');
		}else{
			$this->error('添加失败!');
		}
	}
	//修改界面
	function edit(){
		$db = M('link');
		$result = $db->where("id = ".I('id'))->find();
		if($result){
			$this->content = $result;
		}else{
			$this->error('错误的参数!');
		}
		$this->display();
	}
	//修改成功
	function editok(){
		$db = M('link');
		$db->create();
		$rid = $db->save();
		if($rid){
			$this->success('修改成功！','index');
		}else{
			$this->error('修改失败！');
		}
	}
	//删除界面
	function delete(){
		$content = M('link');
		$rid = $content->where('id = '.I('id'))->delete();
		if($rid){
			$this->success('删除成功！',U('index'));
		}else{
			$this->error('删除失败!');
		}
	}
	//更改显示状态
	public function status(){
		$id = I('id');
		$db = M('link');
		$re = $db->where('id = '.$id)->find();
		if($re){
			switch ($re['status']){
				case 0:
				$db->save(array('id'=>$id,'status'=>1));
				echo '显示';
				break;
				case 1:
				$db->save(array('id'=>$id,'status'=>0));
				echo '隐藏';
				break;
				default:
				break;
			}
		}
	}

	
}